// 覆盖extjs
Ext.QuickTips.init();

Ext.BLANK_IMAGE_URL = EXT_HOME + "/resources/images/default/s.gif";

Ext.Ajax.on('requestexception', function(conn, response, options){
	var json = Ext.decode(response.responseText);
	if (json.success !== true) {
		Utils.msg('出错了：' + json.msg);
		return;
	}
}, this);

// 应用中所有的扩展
Ext.ns('App');
App.LoaderCache = {
	cache: {},
	put: function(files) {
		var arr = [];
		Ext.each(files, function(f){
			if (!this.exists(f)) {
				arr.push(f);
			}
		}, this)
		Ext.Loader.load(arr, function(){
			Ext.each(arr, function(a){
				this.cache[a] = this.HOLD;
			}, this);
		}, this, true);
	},
	exists: function(src){
		return this.cache[src] == this.HOLD;
	}
};

Ext.Module  = function(config){
	Ext.apply(this, config);
	
}
/*
{
	dependencies: [],
	constructor: function(config){
 		if (this.dependencies.length > 0) {
			App.Loader.load(this.dependencies, function(){
				App.Panel.superclass.constructor.apply(this, config);
			}, this);
		} else {
			App.Panel.superclass.constructor.apply(this, config);
		}
	}
});
*/

// 工具方法
Utils = {
	window : function(config) {
		var cfg = {}, callback = config.callback || null;

		Ext.apply(cfg, config);
		Ext.applyIf(cfg, {
			layout : 'fit',
			width : 400,
			height : 300,
			border : false,
			frame : true,
			modal : true,
			buttonAlign : 'center',
			buttons : [ {
				text : '确定',
				ref: '/okBtn',
				handler : function(btn) {
					if (callback && Ext.isFunction(callback.fn)) {
						callback.fn.call(callback.scope || window, btn.refOwner);
					}
				}
			}, {
				text : '取消',
				ref: '/cancelBtn',
				handler : function(btn) {
					btn.refOwner.close();
				}
			}]
		});
		return new top.Ext.Window(cfg).show();
	},

	request : function(config) {
		var c = Ext.apply({}, config), s = config.success;
		c.success = function(response, options){
			var json = Ext.decode(response.responseText);
			if (json.success !== true) {
				Utils.msg('出错了：' + json.msg);
				return;
			}
			s.call(config.scope || window, json, options);
		};
		Ext.Ajax.request(c);
	},

	msg : function(msg) {
		alert(msg + '\t');
	}
};

